﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.Customer;
using SystemCenterSoa.PoModel.Customer;
using SystemCenterSoa.Service.CustomerManager;

namespace SystemCenterSoa.ApiProject.Area.CustomerManager
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CustomerController : SystemManagerBaseController
    {
        private CustomerService _customerService;

        public CustomerController(CustomerService customerService)
        {
            _customerService = customerService;
        }
        [HttpPost]
        public ResultModel<bool> CustomerAdd(CustomerPo info)
        {
            try
            {
                var data = _customerService.CustomerAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> FirstPartyAdd(FirstPartyPo info)
        {
            try
            {
                info.first_create_time = DateTime.Now;
                info.first_create_people = "gzb";
                info.first_update_time = DateTime.Now;
                var data = _customerService.FirstPartyAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }


        [HttpPost]
        public ResultModel<bool> SatisfactionSurveyAdd(SatisfactionSurveyPo info)
        {
            try
            {
                var data = _customerService.SatisfactionSurveyAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }
        //[HttpGet]
        //[AllowAnonymous]
        //public ResultModel<List<StateCityPo>> GetStateCity(int id)
        //{
        //    try
        //    {
        //        var data = _customerService.GetStateCity(id);
        //        return MyOk(data);
        //    }
        //    catch (Exception ex)
        //    {

        //        return MyError<List<StateCityPo>>(ex);
        //    }
        //}
        /// <summary>
        /// 三级联动
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public ResultModel<List<China>> GetChina(int id)
        {
            try
            {
                var data = _customerService.GetChina(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<China>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<FirstPartyPo>> GetFirstParty()
        {
            try
            {
                var data = _customerService.GetFirstParty();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<FirstPartyPo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<CustomerPo>> Tian(int id)
        {
            try
            {
                var data = _customerService.Tian(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<CustomerPo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<SatisfactionSurveyPo>> GetSatisfactionSurveyPos()
        {
            try
            {
                var data = _customerService.GetSatisfactionSurveyPos();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<SatisfactionSurveyPo>>(ex);
            }
        }

        [HttpGet]

        public ResultModel<FirstPartyPo> FanFirst(int id)
        {
            try
            {
                var data = _customerService.FanFirst(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<FirstPartyPo>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> DeleFirst(int id)
        {
            try
            {
                var data = _customerService.DeleFirst(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> UpdateFirst(FirstPartyPo info)
        {
            try
            {
                var data = _customerService.UpdateFirst(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> Deleman(int id)
        {
            try
            {
                var data = _customerService.Deleman(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> Updateman(SatisfactionSurveyPo info)
        {
            try
            {
                var data = _customerService.Updateman(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }
        [HttpGet]
        public ResultModel<SatisfactionSurveyPo> ManCha(int id)
        {
            try
            {
                var data = _customerService.ManCha(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<SatisfactionSurveyPo>(ex);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public ResultModel<PagerResult<CustomerDto>> GetAllInfo(SearchModel searchModel)
        {

            try
            {
                var list = _customerService.GetAllInfo(searchModel);
                return MyOk(list);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<CustomerDto>>(ex);
            }
        }

        [HttpGet]

        public ResultModel<CustomerPo> FanCustomer(int id)
        {
            try
            {
                var data = _customerService.FanCustomer(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<CustomerPo>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<FirstPartyPo>> Fanjia(int id)
        {
            try
            {
                var data = _customerService.Fanjia(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<FirstPartyPo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<SatisfactionSurveyPo>> Fanman(int id)
        {
            try
            {
                var data = _customerService.Fanman(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<SatisfactionSurveyPo>>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> CustomerUpdate(CustomerPo info)
        {
            try
            {
                var data = _customerService.CustomerUpdate(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> Dele(string ids)
        {
            try
            {
                var data = _customerService.Dele(ids);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }
    }
}
